{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "import tensorflow as tf"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "8.0\n"
     ]
    }
   ],
   "source": [
    "# 占位符的使用\n",
    "data1 = tf.placeholder(tf.float32)\n",
    "data2 = tf.placeholder(tf.float32)\n",
    "add = tf.add(data1,data2)\n",
    "with tf.Session() as sess:\n",
    "    print(sess.run(add,feed_dict={data1:6,data2:2}))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(3, 2)\n",
      "[[1 2]\n",
      " [3 4]\n",
      " [5 6]]\n",
      "[1 2]\n",
      "[1 3 5]\n",
      "1\n"
     ]
    }
   ],
   "source": [
    "# 一个一行两列的矩阵[[6,6]],两行两列[[1,1],[2,2]]\n",
    "data1 = tf.constant([[6,6]])\n",
    "data2 = tf.constant([[2],\n",
    "                     [2]])\n",
    "data3 = tf.constant([[3,3]])\n",
    "data4 = tf.constant([[1,2],\n",
    "                     [3,4],\n",
    "                     [5,6]])\n",
    "# 查看矩阵维度\n",
    "print(data4.shape)\n",
    "with tf.Session() as sess:\n",
    "    # 打印整体\n",
    "    print(sess.run(data4))\n",
    "    # 打印第0行\n",
    "    print(sess.run(data4[0]))\n",
    "    # 打印第0列\n",
    "    print(sess.run(data4[:,0]))\n",
    "    # 打印第0行第0列\n",
    "    print(sess.run(data4[0,0]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[24]]\n",
      "[[9 9]]\n",
      "[[12 12]\n",
      " [12 12]]\n"
     ]
    }
   ],
   "source": [
    "# 矩阵乘法\n",
    "matMul = tf.matmul(data1,data2)\n",
    "# 矩阵加法\n",
    "matAdd = tf.add(data1,data3)\n",
    "# 一般乘法，即基于广播机制的乘法\n",
    "matAdd2 = tf.multiply(data1,data2)\n",
    "with tf.Session() as sess:\n",
    "    print(sess.run(matMul))\n",
    "    print(sess.run(matAdd))\n",
    "    print(sess.run(matAdd2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
